<%--
  Created by IntelliJ IDEA.
  User: feng
  Date: 2023/5/12
  Time: 19:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <!-- 页面meta -->
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>体育馆管理系统</title>
  <meta name="description" content="体育馆管理系统">
  <meta name="keywords" content="体育馆管理系统">
  <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
  <!-- 引入样式 -->
  <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/plugins/elementui/index.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/plugins/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/css/style.css">
  <!-- 引入组件库 -->
  <script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/jquery.min.js"></script>
  <script src="<%=request.getContextPath()%>/resources/js/vue.js"></script>
  <script src="<%=request.getContextPath()%>/resources/plugins/elementui/index.js"></script>
  <script src="<%=request.getContextPath()%>/resources/js/axios-0.18.0.js"></script>
  <style>
    .datatable {
      position: relative;
      box-sizing: border-box;
      -webkit-box-flex: 1;
      width: 100%;
      max-width: 100%;
      font-size: 14px;
      color: rgb(96, 98, 102);
      overflow: hidden;
      flex: 1 1 0%;
    }
    .datatable td, .datatable th {
      padding: 12px 0;
      min-width: 0;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      text-overflow: ellipsis;
      vertical-align: middle;
      position: relative;
      text-align: left;
    }
  </style>
</head>
<body class="hold-transition">
<div id="app">
  <div class="content-header">
    <h1>人员档案管理<small>人员档案管理</small></h1>
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item :to="{ path: '/1-1' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>人员档案管理</el-breadcrumb-item>
      <el-breadcrumb-item>基本管理</el-breadcrumb-item>
    </el-breadcrumb>
  </div>
  <div class="app-container">
    <div class="box">
      <div class="filter-container">
        <el-input placeholder="账号/真实姓名" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
        <el-select v-model="pagination.userRole" placeholder="请选职位">
          <el-option label="全部" value="全部"></el-option>
          <el-option label="管理员" value="管理员"></el-option>
          <el-option label="教职工" value="教职工"></el-option>
          <el-option label="学生" value="学生"></el-option>
        </el-select>
        <el-button @click="findPage()" class="dalfBut">查询</el-button>
        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
      </div>
      <el-table size="small" current-row-key="studentNo" :data="dataList" stripe highlight-current-row>
        <el-table-column type="index" align="center" label="序号"></el-table-column>
        <el-table-column prop="userNo" label="账号" align="center"></el-table-column>
        <el-table-column prop="realName" label="姓名" align="center"></el-table-column>
        <el-table-column prop="userRole" label="职位" align="center"></el-table-column>
        <el-table-column prop="recordRemark" label="备注" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="handleUpdateMess(scope.row)">详情</el-button>
            <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">修改</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination
                class="pagiantion"
                @current-change="handleCurrentChange"
                :current-page="pagination.pageNow"
                :page-size="pagination.pageSize"
                layout="total, prev, pager, next, jumper"
                :total="pagination.total">
        </el-pagination>
      </div>
      <!-- 新增标签弹层 -->
      <div class="add-form">
        <el-dialog title="新增场地" :visible.sync="dialogFormVisible">
          <template>
            <el-tabs v-model="activeName" type="card">
              <el-tab-pane label="基本信息" name="first">
                <el-form label-position="right" label-width="100px">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="账号">
                        <el-input v-model="formData.userNo"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="姓名">
                        <el-input v-model="formData.realName"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="登录密码">
                        <el-input v-model="formData.userPassword"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="电话">
                        <el-input v-model="formData.telephone"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="职位">
                        <el-select v-model="formData.userRole" placeholder="请选职位">
                          <el-option label="超级管理员" value="超级管理员"></el-option>
                          <el-option label="场地管理员" value="场地管理员"></el-option>
                          <el-option label="赛事管理员" value="赛事管理员"></el-option>
                          <el-option label="器材管理员" value="器材管理员"></el-option>
                          <el-option label="场地管理员" value="场地管理员"></el-option>
                          <el-option label="公告管理员" value="公告管理员"></el-option>
                          <el-option label="系统管理员" value="系统管理员"></el-option>
                          <el-option label="教职工" value="教职工"></el-option>
                          <el-option label="学生" value="学生"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="备注">
                        <el-input v-model="formData.recordRemark" type="textarea"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </el-tab-pane>
            </el-tabs>
          </template>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取消</el-button>
            <el-button type="primary" @click="handleAdd()">确定</el-button>
          </div>
        </el-dialog>
      </div>

      <!-- 编辑标签弹层 -->
      <div class="add-form">
        <el-dialog title="编辑场地" :visible.sync="dialogFormVisible4Edit">
          <template>
            <el-tabs v-model="activeName" type="card">
              <el-tab-pane label="基本信息" name="first">
                <el-form label-position="right" label-width="100px">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="账号">
                        <el-input v-model="formData.userNo"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="姓名">
                        <el-input v-model="formData.realName"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="登录密码">
                        <el-input v-model="formData.userPassword"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="电话">
                        <el-input v-model="formData.telephone"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="职位">
                        <el-select v-model="formData.userRole" placeholder="请选职位">
                          <el-option label="超级管理员" value="超级管理员"></el-option>
                          <el-option label="场地管理员" value="场地管理员"></el-option>
                          <el-option label="赛事管理员" value="赛事管理员"></el-option>
                          <el-option label="器材管理员" value="器材管理员"></el-option>
                          <el-option label="场地管理员" value="场地管理员"></el-option>
                          <el-option label="公告管理员" value="公告管理员"></el-option>
                          <el-option label="系统管理员" value="系统管理员"></el-option>
                          <el-option label="教职工" value="教职工"></el-option>
                          <el-option label="学生" value="学生"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="余额">
                        <el-input v-model="formData.userBalance" disabled="true"/>
                      </el-form-item>
                    </el-col>
                  </el-row>

                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="备注">
                        <el-input v-model="formData.recordRemark" type="textarea"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  </el-row>
                </el-form>

              </el-tab-pane>
            </el-tabs>
          </template>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
            <el-button type="primary" @click="handleChange()">确定修改</el-button>
          </div>
        </el-dialog>
      </div>

      <!-- 详情标签弹层 -->
      <div class="add-form">
        <el-dialog title="编辑场地" :visible.sync="dialogFormVisible4EditMess">
          <template>
            <el-tabs v-model="activeName" type="card">
              <el-tab-pane label="基本信息" name="first">
                <el-form label-position="right" label-width="100px">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="账号">
                        <el-input v-model="formData.userNo" disabled="true"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="姓名">
                        <el-input v-model="formData.realName" disabled="true"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="登录密码">
                        <el-input v-model="formData.userPassword" disabled="true"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="电话">
                        <el-input v-model="formData.telephone" disabled="true"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="职位">
                        <el-input v-model="formData.userRole" disabled="true"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="余额">
                        <el-input v-model="formData.userBalance" disabled="true"/>
                      </el-form-item>
                    </el-col>
                    <el-row>
                      <el-col :span="24">
                        <el-form-item label="备注">
                          <el-input v-model="formData.recordRemark" type="textarea" disabled="true"></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-row>
                </el-form>

              </el-tab-pane>
            </el-tabs>
          </template>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible4EditMess = false">确定</el-button>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</div>
</body>

<script>
  var vue = new Vue({
    el: '#app',
    data:{
      activeName:'first',//添加/编辑窗口Tab标签名称
      pagination: {//分页相关属性
        pageNow: 1,
        pageSize:10,
        total:100,
        queryString:null,
      },
      dataList: [],//列表数据
      formData: {},//表单数据
      tableData:[],//新增和编辑表单中对应的检查项列表数据
      checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
      dialogFormVisible: false,//控制添加窗口显示/隐藏
      dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
      dialogFormVisible4EditMess:false//控制编辑窗口显示/隐藏
    },
    created() {
      this.findPage();
    },
    methods: {
      //编辑
      handleChange() {
        this.$confirm('是否确定修改该用户信息?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          //发送ajax请求，提交模型数据
          axios.post("<%=request.getContextPath()%>/record/change.do",this.formData).then((response)=> {
            //隐藏编辑窗口
            this.dialogFormVisible4Edit = false;
            if(response.data.success){
              this.$message({
                message: response.data.data,
                type: 'success'
              });
            }else{
              this.$message.error(response.data.data);
            }
          }).finally(()=> {
            this.findPage();
          });
        }).catch(() => {
          // 点击取消进行的操作
        })

      },
      //添加
      handleAdd () {
        //发送ajax请求将模型数据提交到后台处理
        this.$confirm('是否确定添加该用户?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          var permissionID = "";
          if(this.formData.userRole === "超级管理员"){
            permissionID = 11;
          }else if(this.formData.userRole === "场地管理员"){
            permissionID = 21;
          }else if(this.formData.userRole === "赛事管理员"){
            permissionID = 22;
          }else if(this.formData.userRole === "器材管理员"){
            permissionID = 23;
          }else if(this.formData.userRole === "公告管理员"){
            permissionID = 24;
          }else if(this.formData.userRole === "系统管理员"){
            permissionID = 25;
          }else if(this.formData.userRole === "教职工"){
            permissionID = 31;
          }else if(this.formData.userRole === "学生"){
            permissionID = 41;
          }else{
            permissionID = 41;//异常默认为学生
          }
          this.formData.permissionID = permissionID;
          axios.post("<%=request.getContextPath()%>/record/add.do",this.formData)
                  .then((response)=> {
                    //关闭新增窗口
                    this.dialogFormVisible = false;
                    if(response.data.success){
                      //新增成功，弹出成功提示
                      this.$message({
                        message: response.data.data,
                        type: 'success'
                      });
                    }else{
                      //新增失败，弹出错误提示
                      this.$message.error(response.data.data);
                    }
                  }).finally(()=> {
            this.findPage();
          });
        }).catch(() => {
          // 点击取消进行的操作
        })

      },
      //分页查询
      findPage() {
        //分页参数
        var userRoleStart = null;
        var userRoleEnd = null;

        if(this.pagination.userRole === "管理员"){
          userRoleStart = 0;
          userRoleEnd = 30;
        }else if(this.pagination.userRole === "教职工"){
          userRoleStart = 30;
          userRoleEnd = 40;
        }else if(this.pagination.userRole === "学生"){
          userRoleStart =40;
          userRoleEnd = 50;
        }else if(this.pagination.userRole === "全部"){
          userRoleStart =null;
          userRoleEnd = null;
        }else{
          userRoleStart = null;
          userRoleEnd = null;
        }
        var param = {
          pageNow:this.pagination.pageNow,//页码
          pageSize:this.pagination.pageSize,//每页显示的记录数
          userNo:this.pagination.queryString,//查询条件
          realName:this.pagination.queryString,//查询条件
          userRoleStart:userRoleStart,
          userRoleEnd:userRoleEnd
          //queryString:this.pagination.queryString//查询条件
        };
        console.log(param);

        //请求后台
        axios.post("<%=request.getContextPath()%>/record/find.do",param).then((response)=> {
          //为模型数据赋值，基于VUE的双向绑定展示到页面
          console.log(response.data.data.rows);
          this.dataList = response.data.data.rows;
          this.pagination.total =  response.data.data["totalCount"];
        });
      },
      // 重置表单
      resetForm() {
        this.formData = {};
      },
      // 弹出添加窗口
      handleCreate() {
        this.resetForm();
        this.dialogFormVisible = true;
        //默认切换到第一个标签页（基本信息）
        this.activeName='first';
        //重置
        this.checkitemIds = [];
      },
      // 弹出编辑窗口
      handleUpdate(row) {
        var param = {
          userNo:row["userNo"]//查询条件
        };
        axios.post("<%=request.getContextPath()%>/record/find.do",param).then((res)=>{
          if(res.data.data.rows.length === 1){
            //弹出编辑窗口
            this.dialogFormVisible4Edit = true;
            //为模型数据赋值，通过VUE数据双向绑定进行信息的回显
            this.formData={};
            console.log(res.data.data.rows[0]);
            this.formData = res.data.data.rows[0];
          }else{
            this.$message.error("获取数据失败，请刷新当前页面");
          }
        });
      },
      // 弹出详情窗口
      handleUpdateMess(row) {
        var param = {
          userNo:row["userNo"]//查询条件
        };
        axios.post("<%=request.getContextPath()%>/record/find.do",param).then((res)=>{
          if(res.data.data.rows.length === 1){
            //弹出编辑窗口
            this.dialogFormVisible4EditMess = true;
            //为模型数据赋值，通过VUE数据双向绑定进行信息的回显
            this.formData={};
            console.log(res.data.data.rows[0]);
            this.formData = res.data.data.rows[0];
          }else{
            this.$message.error("获取数据失败，请刷新当前页面");
          }
        });
      },
      //切换页码
      handleCurrentChange(pageNow) {
        //pageNow为切换后的页码
        this.pagination.pageNow = pageNow;
        this.findPage();
      },
      // 删除
      handleDelete(row) {
        this.$confirm('是否确定删除该用户?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          var param = {
            userNo:row["userNo"]
          };
          axios.post("<%=request.getContextPath()%>/record/delete.do",param).then((res)=>{
            if(res){
              this.$message({
                message: res.data.data,
                type: 'success'
              });
            }else{
              this.$message.error("删除失败");
            }
          }).finally(()=> {
            this.findPage();
          });
        }).catch(() => {
          // 点击取消进行的操作
        })

      }
    }
  })
</script>
</html>


